package com.dingding.special.user.vehicle.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.special.user.vehicle.dao.ISpecialVehicleDao;
import com.dingding.special.user.vehicle.dto.ResSpecialVehicleDTO;
import com.dingding.special.user.vehicle.sql.SpecialVehicleSQL;

/**
 * 
 * @ClassName: SpecialVehicleDaoImpl 
 * @Description: 专车车辆DAO实现类
 * @author YHQ
 * @date 2016年8月25日 上午9:37:59
 * @since V2.4.0
 * 
 */
@Component("specialVehicleDao")
public class SpecialVehicleDaoImpl implements ISpecialVehicleDao{

	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource(name="SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;
	
	/**
	 * 
	 * @Title: getVehicleInfo 
	 * @Description: 获取车辆信息
	 * @param userId 根据用户Id
	 * @author YHQ 
	 * @since V2.4.0
	 * @return ResSpecialVehicleDTO    返回类型
	 * 
	 */
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public ResSpecialVehicleDTO getVehicleInfo(String userId) {
		
		try {
			
			// 获取车辆信息
			List<ResSpecialVehicleDTO> specialVehicleDTOs = sqlBaseDao.listSqlToCustomBean(ResSpecialVehicleDTO.class, SpecialVehicleSQL.GET_SPECIAL_VEHICLE_INFO, userId);
			
			if(specialVehicleDTOs != null && specialVehicleDTOs.size() > 0){
				
				ResSpecialVehicleDTO dto = specialVehicleDTOs.get(0);
				
				dto.setJszImage(ToolUtil.imageAddress(dto.getJszImage()));
				dto.setXszImage(ToolUtil.imageAddress(dto.getXszImage()));
				dto.setVehicleImage(ToolUtil.imageAddress(dto.getVehicleImage()));
				
				return specialVehicleDTOs.get(0);
			}
			
		} catch (Exception e) {
			log.error("获取车辆信息时出现异常   类："+this.getClass(), e);
		}
		
		return null;
	}

	
	
}
